

<template>
  <div class="yrdh">
    <div class="btn2">
      <el-button type="primmary" @click="deleteAllUserHandler"
       >删除</el-button>
      <el-button type="primmary" @click="addCourtyard(0)">新增院区</el-button>

    </div>
    <div class="form_data">
      <searchData :loadData="setPage" :currentPage="currentPage" :pageSize="pageSize1" />
    </div>
    <div>
      <formdata @onselectUserIds="selectUserIdsHandler"
      :tabledata="data" :total="total" :loadData="setPage" :currentPage="currentPage" :pageSize="pageSize1" />
    </div>
  </div>
</template>
  
<script setup lang="ts">
import { ref } from 'vue'
import formdata from './ui/formData.vue';
import searchData from './ui/searchData.vue';
import useHospitalUserList from '../../hooks/useHospitalUserList'
import {ElMessage,ElMessageBox} from 'element-plus' 
import { useRouter } from 'vue-router'
import {deleteAllUserApi} from '@/api/hospitalApi'
const [currentPage,data,total,pageSize1,loadData]=useHospitalUserList()
const setPage = (page: number = 1, size: number = 10,form?:any) => {
  loadData(page, size,form)
}
const dialogVisible=ref(false);
const importUserHandle = () => {
  dialogVisible.value=true;  
}
const selectUserIds=ref<number[]>([])
const selectUsers=ref<any[]>([])
const selectUserIdsHandler=(ids:number[],users:any[])=>{
  selectUserIds.value=ids
  selectUsers.value=users
  
}
const deleteAllUserHandler=async ()=>{
  ElMessageBox.confirm(
    '您真的要删除此所选用户信息吗？?',
    '提示',
    {
      confirmButtonText: '确定删除',
      cancelButtonText: '取消删除',
      type: 'warning',
    }
  )
    .then(async () => {
      if(selectUserIds.value.length!==0){
        let ret = await deleteAllUserApi(selectUserIds.value)
        if(ret.code==0){
        loadData(currentPage.value, pageSize1.value,undefined)
        }
      }
      // ElMessage({
      //   type: 'success',
      //   message: '删除成功',
      // })
    })
    .catch(() => {
      ElMessage({
        type: 'info',
        message: '删除失败',
      })
    })
}
const router=useRouter()
const addCourtyard=(id:number)=>{
  router.push(`/hospital/yrdh/Counrtyard/${id}`)
}
</script>
  
<style scoped>
/* 样式代码 */
.form_data {
  width: 100%;
  height: 60px;
}

.yrdh {
  margin: 18px 18px;
  /* background-color: black; */
  height: 480px;
  position: relative;

  .btn2 {
    float: right;
    margin-right: 15px;
    padding-top: 20px;
    position: absolute;
    top: -80px;
    right: 15px;
  }
}
.upload-excel-box {
  height: 300px;
  width: 300px;
  border: 3px dashed #ccc;
  display: flex;
  justify-content: center;
  align-items: center;
  font-size: 18px;
  margin: 0 auto;
}
</style>